home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 19 / develop 19 code / SimpliFace_V2 / Sources / ListOfLongs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-15  |  2.8 KB  |  120 lines  |  [TEXT/MPS ]

  1.  
  2. /*
  3.     File:        ListOfLongs.h
  4.  
  5.     Contains:    TListOfLongs interface
  6.  
  7.  
  8.     Developed by:
  9.  
  10.     Paul G Smith (commstalk hq & Full Moon Software, Inc)
  11.  
  12.     you can leave messages at (UK): 0727 844232; (US): 408 253 7199
  13.     BUT I prefer to be contacted by e-mail
  14.     AppleLink:     COMMSTALK.HQ
  15.     Internet:     COMMSTALK.HQ@applelink.apple.com
  16.  
  17.     "SimpliFace2" Sample code to accompany develop article
  18.     on techniques for controlling script inheritance.
  19.     
  20.     
  21.  
  22.  
  23.     Ordered and un-ordered lists of long integers
  24.  
  25. */
  26.  
  27. #ifndef __LISTOFLONGS__
  28. #define __LISTOFLONGS__
  29.  
  30.  
  31. #ifndef __MEMORY__
  32. #include <Memory.h>
  33. #endif
  34.  
  35.  
  36.  
  37.  
  38.  
  39. /**********************************************************************
  40. ** class TListOfLongs
  41. **     Sorted list of long integers (for un-ordered applications)
  42. ***********************************************************************/
  43.  
  44. class TListOfLongs
  45. {    
  46. public:
  47.                     TListOfLongs(void);        // constructor
  48.                     TListOfLongs(const TListOfLongs&);
  49.                     ~TListOfLongs(void);    // destructor
  50.     TListOfLongs&    operator=(const TListOfLongs&);
  51.     
  52.             Handle    GetData(void);                // saves data to handle
  53.             void    SetData(Handle h);            // loads data from handle
  54.     
  55.             long    CountElements(void);
  56.     virtual OSErr    InsertElement(long val);
  57.             void    DeleteElement(long val);
  58.             long    GetElement(long index);
  59.     virtual long    FindElement(long val);         // returns index, or 0 if not found
  60.     
  61. protected:
  62.     long            fNumItems;
  63.     Handle            fDataHandle;
  64.     
  65.             OSErr    ExpandDataHandle(long numLongs);
  66.             OSErr    ShrinkDataHandle(long numLongs);    
  67. };
  68.  
  69.  
  70.  
  71. inline long TListOfLongs::CountElements(void)
  72. {
  73.     return fNumItems;
  74. }
  75.  
  76.  
  77.  
  78. /**********************************************************************
  79. ** class TOrderedListOfLongs
  80. **     Un-sorted list of long integers (for ordered applications)
  81. ***********************************************************************/
  82.  
  83. class TOrderedListOfLongs : public TListOfLongs
  84. {
  85. public:
  86.                             TOrderedListOfLongs(void);        // constructor
  87.                             TOrderedListOfLongs(const TListOfLongs&);
  88.                             ~TOrderedListOfLongs(void);    // destructor
  89.     TOrderedListOfLongs&    operator=(const TOrderedListOfLongs&);
  90.     
  91.     virtual OSErr    InsertElement(long val);
  92.             OSErr    InsertElementAt(long val, long index);
  93.     virtual long    FindElement(long val);         // returns index, or 0 if not found
  94. };
  95.  
  96.  
  97. /**********************************************************************
  98. ** class TStackOfLongs
  99. **     Un-sorted stack of long integers (for ordered applications)
  100. ***********************************************************************/
  101.  
  102. class TStackOfLongs : public TListOfLongs
  103. {
  104. public:
  105.                             TStackOfLongs(void);        // constructor
  106.                             TStackOfLongs(const TListOfLongs&);
  107.                             ~TStackOfLongs(void);    // destructor
  108.     TStackOfLongs&            operator=(const TStackOfLongs&);
  109.  
  110.             OSErr    PushElement(long val);
  111.             OSErr    PopElement(long *val);
  112.     
  113.     // don't call these functions:
  114.     virtual OSErr    InsertElement(long val);
  115.     virtual long    FindElement(long val);     
  116. };
  117.  
  118.  
  119. #endif
  120.